﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Interfleet.SE.UICompiler.Core
{
    /// <summary>
    /// An implementation of the <see cref="IProcessStartInfoBuilder"/>, primary purpose is to
    /// deliver a start info for the Google Closure Compiler java component.
    /// </summary>
    public class ProcessStartInfoBuilder : IProcessStartInfoBuilder
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="exeFileName">name of the external executable file. Full file path
        /// or just the filename without extension if it is known by the system.</param>
        public ProcessStartInfoBuilder(string exeFileName)
        {
            if (string.IsNullOrEmpty(exeFileName))
            {
                throw new ArgumentNullException("exeFileName", "value cannot be null");
            }
            _exeFileName = exeFileName;
        }

        private string _exeFileName = string.Empty;

        /// <summary>
        /// Builds up a <see cref="System.Diagnostics.ProcessStartInfo"/>
        /// </summary>
        /// <param name="arguments">Command line arguments for the process</param>
        /// <returns>A <see cref="System.Diagnostics.ProcessStartInfo"/></returns>
        ProcessStartInfo IProcessStartInfoBuilder.Build(string arguments)
        {
            var startInfo = new ProcessStartInfo(_exeFileName, arguments);
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.ErrorDialog = false;
            startInfo.CreateNoWindow = true;
            return startInfo;
        }
    }
}
